# from module_exercise import *
# func01()
# mc = MyClass()
# mc.func02()
# mc.func03()
#
# import datetime
# import calendar
#
# # def get_weekday(year, month, day):
# #     date = datetime.date(year, month, day)
# #     weekday = (date.weekday()+1)%7
# #     return weekday
# #
# # year = int(input("请输入年："))
# # month = int(input("请输入月："))
# # day = int(input("请输入日："))
# # print(get_weekday(year, month, day))
#
# def cal_live(year, month, day):
#     date = datetime.date(year, month, day)
#     today = datetime.date.today()
#     days = (today - date).days
#     return days
#
# year = int(input("请输入出生年："))
# month = int(input("请输入出生月："))
# day = int(input("请输入出生日："))
# print(cal_live(year, month, day))
from datetime import time


# def get_score():
#     while True:
#         try:
#             score = int(input("请输入分数："))
#         except Exception as e:
#             print("输入有误")
#         else:
#             return score
#
# score = get_score()
# print(f'成绩是：{score}')
#
# class Wife:
#     def __init__(self, age):
#         self.age = age
#
#     @property
#     def age(self):
#         return self.__age
#
#     @age.setter
#     def age(self, value):
#         if 20 <= value <= 60:
#             self.__age = value
#         else:
#             raise Exception("我不要","if 20 <= value <= 60", 1001)
#
# while True:
#     try:
#         age = int(input("请输入年龄："))
#         wife = Wife(age)
#         print(f"老婆的年龄是：{wife.age}")
#         break
#     except Exception as e:
#         print(e)
#
# message = "我是花果山水帘洞孙悟空"
# # for item in message:
# #     print(item)
# iterator = message.__iter__()
# while True:
#     try:
#         item = iterator.__next__()
#         print(item)
#     except StopIteration:
#         break

# mylist = [1,2,3,4,5,6,7,8,9]
# mylist_iterator = mylist.__iter__()
# while True:
#     try:
#         item = mylist_iterator.__next__()
#         print(item)
#     except StopIteration:
#         break

# mydict = {"a":1, "b":2, "c":3}
# mydict_items = mydict.items()
# mydict_iterator = iter(mydict_items)
# while True:
#     try:
#         key_value = mydict_iterator.__next__()
#         print(key_value)
#     except StopIteration:
#         break

class StudentIterator:
    def __init__(self, data):
        self.__data = data
        self.__index = -1

    def __next__(self):
        if self.__index == len(self.__data) - 1:
            raise StopIteration
        self.__index += 1
        return self.__data[self.__index]


class StudentController:
    def __init__(self):
        self.__students = []

    def add_student(self, stu):
        self.__students.append(stu)

    def __iter__(self):
        return StudentIterator(self.__students)


# controller = StudentController()
# controller.add_student('wukong')
# controller.add_student('bajie')
# controller.add_student('tangseng')
# iterator = controller.__iter__()
# while True:
#     try:
#         item = iterator.__next__()
#         print(item)
#     except StopIteration:
#         break

# class CommodityIterator:
#     def __init__(self, data):
#         self.__data = data
#         self.__index = -1
#
#     def __next__(self):
#         if self.__index == len(self.__data)-1:
#             raise StopIteration
#         self.__index += 1
#         return self.__data[self.__index]
#
# class CommodityController:
#     def __init__(self):
#         self.__commodity_list = []
#
#     def add_commodity(self, commodity):
#         self.__commodity_list.append(commodity)
#
#     def __iter__(self):
#         return CommodityIterator(self.__commodity_list)
#
# controller = CommodityController()
# controller.add_commodity("屠龙刀")
# controller.add_commodity("倚天剑")
# controller.add_commodity("芭比娃娃")
# for item in controller:
#     print(item)

# class GraphicIterator:
#     def __init__(self, graphics):
#         self.__graphic_list = graphics
#         self.__index = -1
#
#     def __next__(self):
#         if self.__index == len(self.__graphic_list)-1:
#             raise StopIteration
#         self.__index += 1
#         return self.__graphic_list[self.__index]
#
# class GraphicController:
#     def __init__(self):
#         self.__graphics = []
#
#     def add_graphic(self, graphic):
#         self.__graphics.append(graphic)
#
#     def __iter__(self):
#         return GraphicIterator(self.__graphics)
#
# controller = GraphicController()
# controller.add_graphic("圆形")
# controller.add_graphic("矩形")
# controller.add_graphic ("三角形")
# for item in controller:
#     print(item)

# class RangeIterator:
#     def __init__(self, range):
#         self.__range = range
#         self.__index = -1
#
#     def __next__(self):
#         if self.__index == self.__range-1:
#             raise StopIteration
#         self.__index += 1
#         return self.__index
# class MyRange:
#     def __init__(self, range):
#         self.__range = range
#
#     def __iter__(self):
#         return RangeIterator(self.__range)
#
# for number in MyRange(5):
#     print(number)

# def my_range(stop):
#     number = 0
#     while number < stop:
#         yield number
#         number += 1
#
# for number in my_range(5):
#     print(number)

# def look_for_event_numbers(nl):
#     for number in nl:
#         if number % 2 == 0:
#             yield number
#
# for num in look_for_event_numbers([43,43,54,56,76,87,98]):
#     print(num)

# def look_for_number(ml):
#     for item in ml:
#         if isinstance(item, int):
#             yield item
#
# for item in look_for_number([43,"悟空",True,56,"八戒",87.5,98]):
#     print(item)

list01 = [43, 43, 54, 56, 76]


# for item in list01:
#     print(item)
#
# for i in range(len(list01)):
#     if list01[i] % 2 == 0:
#         list01[i] += 1
#
# for i, item in enumerate(list01):
#     if item % 2 == 0:
#         list01[i] += 1

# for i in range(len(list01) - 1):
#     if list01[i] % 2 == 1:
#         list01[i] = None

# for i, item in enumerate(list01):
#     if item % 2 == 0:
#         list01[i] += 1
# print(list01)

# list_student_name = ["悟空", "八戒", "白骨精"]
# list_student_age = [28, 25, 36]
# list_student_sex = ["男", "男", "女"]
# new_map = [item for item in zip(list_student_name, list_student_age)]
# print(new_map)

# list01 = [43, "a", 5, True, 6, 7, 89, 9, "b"]
# char_list = [item for item in list01 if isinstance(item, str)]
# print(char_list)
#
# square_list = [item ** 2 for item in list01 if isinstance(item, int)]
# print(square_list)

# list01 = [342, 4, 54, 56, 6776, 15]
# def divide_3(num):
#     return num % 3 == 0
#
# def divide_5(num):
#     return num % 5 == 0
#
# def find_single(nums):
#     for num in nums:
#         if divide_3(num) and divide_5(num):
#             return num
#
# print(find_single(list01))

class Employee:
    def __init__(self, eid, did, name, money):
        self.eid = eid  # 员工编号
        self.did = did  # 部门编号
        self.name = name
        self.money = money


list_employees = [
    Employee(1001, 9002, "师父", 60000),
    Employee(1002, 9001, "孙悟空", 50000),
    Employee(1003, 9002, "猪八戒", 20000),
    Employee(1004, 9001, "沙僧", 30000),
    Employee(1005, 9001, "小白龙", 15000),
]


# def get_eid1003(emp):
#     return emp.eid == 1003
#
# def get_name_sunwukong(emp):
#     return emp.name == "孙悟空"
#
# def find_all(emps):
#     for emp in emps:
#         if get_eid1003(emp) or get_name_sunwukong(emp):
#             yield emp
#
# for emp in find_all(list_employees):
#     print(emp.__dict__)
#
# for item in map(lambda item: item.name, list_employees):
#     print(item)
#
# for item in filter(lambda item: item.did == 9002, list_employees):
#     print(item.__dict__)
#
# emp = max(list_employees, key=lambda emp: emp.money)
# print(emp.money)
#
# new_list = sorted(list_employees, key=lambda emp: emp.money)
# print(new_list)

# class Commodity:
#     def __init__(self, cid=0, name="", price=0):
#         self.cid = cid
#         self.name = name
#         self.price = price
# list_commodity_infos = [
#     Commodity(1001, "屠龙刀", 10000),
#     Commodity(1002, "倚天剑", 10000),
#     Commodity(1003, "金箍棒", 52100),
#     Commodity(1004, "口罩", 20),
#     Commodity(1005, "酒精", 30),
# ]
#
# # name_and_price = [(item.name, item.price) for item in list_commodity_infos]
# for item in map(lambda item: (item.name, item.price), list_commodity_infos):
#     print(item)
#
# for item in filter(lambda item: item.price < 10000, list_commodity_infos):
#     print(item.__dict__)
#
# new_list = sorted(list_commodity_infos, key=lambda item: item.price, reverse=True)
# print(new_list)
#
# longest_list = max(([1,1],[2,2,2],[3,3,3]), key=lambda item: len(item))
# print(longest_list)

# def give_gife_money(money):
#     print("获得", money, "元压岁钱")
#     def child_buy(commodity, price):
#         nonlocal money
#         money -= price
#         print("购买", commodity, "花费", price, "元, 余额", money)
#     return child_buy
# action = give_gife_money(100)
# action("口罩", 10)
# action("变形金刚", 200)
# action("芭比娃娃", 300)

# def bank_open(money):
#     print("银行开户存入", money,"元")
#     def buy(commodity,price):
#         nonlocal money
#         money -= price
#         print("购买", commodity, "花费", price, "元, 余额", money)
#     return buy
#
# action = bank_open(10000)
# action("变形金刚", 200)
# action("芭比娃娃", 300)

# def func01():
#     print("old function")
#
# def new_func(func):
#     def wrapper():
#         print("new func")
#         func()
#     return wrapper
#
# func01 = new_func
# func01 = new_func(func01)
# func01()
# func01()

# def verify_permissions(func):
#     def wrapper(*args, **kwargs):
#         print("验证权限")
#         func()
#
#     return wrapper()
#
#
# @verify_permissions
# def insert():
#     print("插入")
#
#
# @verify_permissions
# def delete():
#     print("删除")
#
#
# insert()
# delete()
import time
def get_run_time(func):
    def wrapper(*args, **kwargs):
        start = time.time()
        result = func(*args, **kwargs)
        end = time.time()
        print("耗时：", end - start)
        return result
    return wrapper
@get_run_time
def sum_data(n):
    sum_value = 0
    for number in range(n):
        sum_value += number
    return sum_value
print(sum_data(10))
print(sum_data(1000000))